<template>
  <div>
    <div
      style="font-size: 16px;font-weight: 500;color: #1D2129;margin-bottom: 16px;"
    >
      体校类别
    </div>

    <div style="display: flex; ">
      <img
        src="@/assets/img/Frame@2x.png"
        alt=""
        style="width: 32px;height: 32px; margin-right: 16px;18px;margin-top: 5px"
      />
      <div>
        <div style="font-size: 24px;color: #0F0F0F;">34,201</div>
        <div style="font-size: 12px;">全国体育传统项目学校数量/所</div>
      </div>
    </div>
    <div
      style="height: 40px;width: 100%;background: #F9F9F9;line-height: 40px;margin-top: 16px;"
    >
      <div style="font-size: 12px;color: #165DFF;margin-left: 20px;">
        学校所属重点学校类型
      </div>
    </div>
    <div class="chart-content">
      <div class="chart-area">
        <div class="total-number">47,201</div>
        <div ref="chart2" class="chart-container"></div>
      </div>
      <div class="data-list">
        <div class="data-item" v-for="(item, index) in chartData" :key="index">
          <div class="item-name">
            <span
              class="color-dot"
              :style="{ backgroundColor: item.itemStyle.color }"
            ></span>
            <span>{{ item.name }}</span>
          </div>
          <div class="item-value">{{ formatNumber(item.value) }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "SchoolType",
  data() {
    return {
      chartInstance: null
    };
  },
  mounted() {
    this.datalist();
  },

  methods: {
    datalist() {
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.getElementById("Chart"));
      // 指定图表的配置项和数据
      var option;
      option = {
        tooltip: {
          trigger: "item"
        },
        legend: {
          top: "5%",
          left: "center"
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 2
            },
            label: {
              show: false,
              position: "center"
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: "bold"
              }
            },
            labelLine: {
              show: false
            },
            data: [
              { value: 1048, name: "Search Engine" },
              { value: 735, name: "Direct" },
              { value: 580, name: "Email" },
              { value: 484, name: "Union Ads" },
              { value: 300, name: "Video Ads" }
            ]
          }
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      // 监听父元素大小变化 刷新图表
      var ro = new ResizeObserver(entries => {
        for (let entry of entries) {
          const cr = entry.contentRect;
          myChart.resize();
        }
      });
      ro.observe(cc);
    }
  }
};
</script>

<style scoped>
h2 {
  margin-bottom: 20px;
}
</style>
